#include "punishdialog.h"
#include "ui_punishdialog.h"
#include"qualifydocu.h"
#include<QString>
#include<QDebug>
#include<QMessageBox>
punishDialog::punishDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::punishDialog)
{
    ui->setupUi(this);
    connect(ui->cancel,SIGNAL(clicked(bool)),this,SLOT(close()));
    connect(ui->confirm,SIGNAL(clicked(bool)),this,SLOT(react()));
    connect(ui->confirm,SIGNAL(clicked(bool)),parent,SLOT(showPunishInfo()));
}

punishDialog::~punishDialog()
{
    delete ui;
}
void punishDialog::react(){
    //sqlconnect(db);
    QString pdate=ui->punishdate->text();
    QString pname=ui->punishEdit->text();
    if(pdate.count()==0||pname.count()==0){
        QMessageBox::information(this,"提示信息","输入有空项！");
        return;
        }
    //qDebug()<<rdate;
    QSqlQuery qu("select * from `Punish` WHERE PunishTime='"+pdate+"' and PunishName='"+pname+"' and IDNum='"+ID+"'");
    if(qu.next())
    {
        QMessageBox::information(this,"提示信息","该惩处已存在，不可重复添加！");
        return;
    }

    QSqlQuery query;
    QString sql2="INSERT INTO Punish(PunishTime,PunishName,IDNum)VALUES('"+pdate+"','"+pname+"','"+ID+"')";
    bool ok2=query.exec(sql2);
    //qDebug()<<ok;
    if(ok2){
        QMessageBox::information(this,"提示信息","成功插入!");
    }
    this->close();
}
void punishDialog::reciveID(QString s){
    ID=s;
}
